#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
  int pipefd[2] = {0};
  pipe(pipefd);
  pid_t id = fork();
  if(id > 0)
  {
    close(pipefd[0]);
    const char* msg = "i am father";
    while(1)
    {
      write(pipefd[1], msg, strlen(msg));

      sleep(1);
    }

  }
  else 
  {
    close(pipefd[1]);
    char buffer[64];
    while(1)
    {
      ssize_t ret = read(pipefd[0], buffer, sizeof(buffer)-1);
      if(ret > 0)
      {
        buffer[ret] = '\0';
        printf("%s\n",buffer);
      }
    }
  }
  return 0;
}
